-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ast, parser: fix parse join #1129
Conversation
Signed-off-by: wjhuang2016 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
||
/* A dummy token to force the priority of TableRef production in a join. */ | ||
%left tableRefPriority | ||
%left join straightJoin inner cross left right full natural |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be easier to make the JOIN operator right-associative? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewCrossJoin() will do the reorganization, make it left-associative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i mean if you use %right
here perhaps you don't need that NewCrossJoin()
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then t1 right join t2 right join t3
would be t1 right join (t2 right join t3)
, it's not correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is that incorrect? a RIGHT JOIN b RIGHT JOIN c ON w1 ON w2
is indeed equivalent to a RIGHT JOIN (b RIGHT JOIN c ON w1) ON w2
,
and the same for LEFT JOIN (a LEFT JOIN b LEFT JOIN c ON w1 ON w2
== a LEFT JOIN (b LEFT JOIN c ON w1) ON w2
)
this is different from a RIGHT JOIN b ON w1 RIGHT JOIN c ON w2
which means (a RIGHT JOIN b ON w1) RIGHT JOIN c ON w2
however NATURAL JOIN needs to be left-associative (a NATURAL JOIN b NATURAL JOIN c
== (a NATURAL JOIN b) NATURAL JOIN c
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the example is wrong.
Consider select * from t1 join t2 right join t3 on t2.a=t3.a;
, if using right-associative, we got
select * from t1 join (t2 right join t3 on t2.a=t3.a)
. They are not the same.
select * from t1 join t2 join t3;
mysql> select * from t1 join t2 right join t3 on t2.a=t3.a;
+------+------+------+
| a | a | a |
+------+------+------+
| NULL | NULL | 3 |
+------+------+------+
1 row in set (0.00 sec)
mysql> select * from t1 join (t2 right join t3 on t2.a=t3.a);
+------+------+------+
| a | a | a |
+------+------+------+
| 1 | NULL | 3 |
+------+------+------+
1 row in set (0.00 sec)
Signed-off-by: wjhuang2016 <[email protected]>
Signed-off-by: wjhuang2016 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
/run-all-tests |
Signed-off-by: wjhuang2016 [email protected]
What problem does this PR solve?
Fix pingcap/tidb#20563
We can't parse
t1 join t2 join t3 on xxx on xxx
.Because the order is:
(t1 join t2 join t3 on xxx) on xxx
. What we need ist1 join (t2 join t3 on xxx) on xxx
What is changed and how it works?
join straightJoin inner cross left right full natural
belowtableRefPriority
, which is the same as MySQL.Check List
Tests
Code changes
Side effects
Related changes